package com.hiray.taglayoutmanager;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hiray.taglayoutmanager.uitility.ClickableViewHolder;

/**
 * Created by hiray on 2017/12/15.
 *
 * @author hiray
 */

public class SameItemSizeAdapter extends RecyclerView.Adapter<SameItemSizeAdapter.ViewHolder> {
    private LayoutInflater layoutInflater;
    private Context context;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (layoutInflater == null) {
            context = parent.getContext();
            layoutInflater = LayoutInflater.from(parent.getContext());
        }
        int layoutId = context.getResources().getIdentifier("same" + viewType, "layout", context.getPackageName());
        return new ViewHolder(layoutInflater.inflate(layoutId, parent, false));
    }

    @Override
    public int getItemViewType(int position) {
        return position % 2;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.text.setText(String.valueOf(holder.getAdapterPosition()));
    }

    @Override
    public int getItemCount() {
        return 18;
    }

    class ViewHolder extends ClickableViewHolder {


        TextView text;

         ViewHolder(View itemView) {
            super(itemView);
            text = (TextView) itemView;
        }
    }
}
